0

I am currently working on some online shop so far so good. The only worry is I don't want to use built-in authorization functions. I want to do something different, to use Global.asax file. To catch Request.RawUrl in Application_BeginRequest so in the moment request is sent and to check for a specific folder if it is requested and to redirect back to log in if it is not authorized. The reason why I don't want to use built-in is because of the database. I want my own custom made database because there is many things I have done that I want to have full control of it. Yes, I saw many tutorials as recommended here before. I have searched for this stuff for a few days already saw many tutorials on how to customize those built-in functionalities.

Maybe my question looks complicated but in the end, I will ask simply. Is it safe to intercept each request in Global.asax file? And is it good idea to use Application_BeginRequest or something else?

Thank you kindly, everyone.

2 Answers 2

0

It basically depends on your system and business model, if your every request needs to be authorized, then implement the authorization logic in Application_BeginRequest may meet your need. But in practice, I wouldn't recommend you to take this action, because once you do this, if someday you have a feature that can be access without logging in, then you have to find out another way to break this rule. That means your system will lose flexibility.

I suggest using Authorization filter, you can inherit AuthorizeAttribute class, and override its methods with your customized authorization logic. For more details: Custom Authorization filter in ASP.NET MVC 5?

Sign up to request clarification or add additional context in comments.

2 Comments

i forgot to mention i am using WebForms.
Anyway flexibility is not a problem, all I am thinking is if it is safe to do it there
0

btw here is a simple code that I use

 protected void Application_BeginRequest(object sender, EventArgs e)
    {

        HttpCookie cookie = Request.Cookies["es"];

        if (Request.RawUrl.Contains(@"/admin"))
        {
            if (cookie ==null)
            {
                Response.Redirect("~/login.aspx");

            }
            else
            {
                if (cookie["role"] != "admin")
                {


                    Request.Cookies.Remove("es");

                    Response.Redirect("~/login.aspx");

                }
            }


        }

    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.