我的网页上装满页数,其中大多数需要一些届会变量才能运行。
i 想在我看来采用一些防御守则。 在什么地方,最适于像:
if (Session.Count == 0){
Response.Redirect("~/default.aspx");
}
EDIT:如果目前一页已经消失,如何检查。 页: 1
我的网页上装满页数,其中大多数需要一些届会变量才能运行。
i 想在我看来采用一些防御守则。 在什么地方,最适于像:
if (Session.Count == 0){
Response.Redirect("~/default.aspx");
}
EDIT:如果目前一页已经消失,如何检查。 页: 1
很困难,幸运的是,它得到解决。
页: 1
这里是法典
/// <summary>
/// The event occurs just after Initialization of Session, and before Page_Init event
/// </summary>
protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
// here it checks if session is reuired, as
// .aspx requires session, and session should be available there
// .jpg, or .css doesn t require session so session will be null
// as .jpg, or .css are also http request in any case
// even if you implemented URL Rewritter, or custom IHttp Module
if (Context.Handler is IRequiresSessionState
|| Context.Handler is IReadOnlySessionState)
{
// here is your actual code
// check if session is new one
// or any of your logic
if (Session.IsNewSession
|| Session.Count < 1)
{
// for instance your login page is default.aspx
// it should not be redirected if,
// if the request is for login page (i.e. default.aspx)
if (!Context.Request.Url.AbsoluteUri.ToLower().Contains("/default.aspx"))
{
// redirect to your login page
Context.Response.Redirect("~/default.aspx");
}
}
}
}
www.un.org/Depts/DGACM/index_spanish.htm Edit 1: Explanation & Conclusions
其中一个故事讲述了。
发生了大量事件。
Actually events in Global.asax raises in the following sequence
履行《乌拉圭回合行动计划》
Raise the BeginRequest activity.
Conclusion: All the events before AcquireRequestState event don t have Session object, because Session is not loaded by ASP.Net, so any event from *"AcquireRequestState** event gives Session object therefore this problem solves. However some checks are required as I mentioned in above code
一种方法是在<代码>上设置一个进行这一检查的页基级。 页: 1 另一种方法是将电离层带入Application_AcquireRequestState
中提供。 由于不是标准网络要求,这应使与会者能够参加本届会议,以完成你想要的东西。
http://www.un.org/Depts/DGACM/index_french.htm
总结我们的想法:
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if ((Session.Count == 0) &&
!(Request.Url.AbsolutePath.EndsWith("default.aspx",
StringComparison.InvariantCultureIgnoreCase)))
{
Response.Redirect("~/default.aspx");
}
}
Be careful with your approach. I don t think it is a good idea to validate globally if certain Session information exists or not. It can get become very messy, very fast. Only certain pages might require specific Session variables, which differ from other pages. Further down the road you might even have some content which can be safely accessed without any existing Session state. Then you will have to start coding exceptions to your rule...
你在这些会议上储存哪些信息? 如果你进一步阐述,我们或许可以提出更好的办法。
仔细阅读Session.Count = 0
,因为像会议一样,会议储存在暗中。
最好是看上像<代码>(Session[“UserName”]=无),其中Session[“UserName]
是你明确储存某种用户。
除此以外,Global.asax是最佳地方(ASP.NET 应用程序周期:
<>strong>ALSO, 您必须检查你不是,目前是 on ~/default.aspx,因为否则你会有一个无限的休息室。
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!