如何在asp.net mvc中仅更改一条路由的会话?
如何在asp.net mvc中使用自定义过滤器处理Application_BeginRequest?
我只想恢复一条路由(~/my-url)的会话。
如果我可以创建一个自定义过滤器并处理它,那就太酷了。
protected void Application_BeginRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
if (string.Equals("~/my-url",
context.Request.AppRelativeCurrentExecutionFilePath,
StringComparison.OrdinalIgnoreCase))
{
string sessionId = context.Request.Form["sessionId"];
if (sessionId != null)
{
HttpCookie cookie = context.Request.Cookies.Get("ASP.NET_SessionId");
if (cookie == null)
{
cookie = new HttpCookie("ASP.NET_SessionId");
}
cookie.Value = sessionId;
context.Request.Cookies.Set(cookie);
}
}
How to handle Application_BeginRequest using a custom filter in asp.net mvc?
I want to restore session only for one route (~/my-url).
It would be cool, if I could create a custom filter and handle that.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
if (string.Equals("~/my-url",
context.Request.AppRelativeCurrentExecutionFilePath,
StringComparison.OrdinalIgnoreCase))
{
string sessionId = context.Request.Form["sessionId"];
if (sessionId != null)
{
HttpCookie cookie = context.Request.Cookies.Get("ASP.NET_SessionId");
if (cookie == null)
{
cookie = new HttpCookie("ASP.NET_SessionId");
}
cookie.Value = sessionId;
context.Request.Cookies.Set(cookie);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 IRouteHandler 做到了。
这是在 global.asax 中(abc/qwr 是路线):
有什么意见吗?
I did it using IRouteHandler.
This is in global.asax (abc/qwr is the route):
Any comments?