FormAuthentication on ascx files

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default FormAuthentication on ascx files

    Hi,

    I have a default.aspx page which has PlaceHolder where it will call
    different *.acx file based on the request url.
    eg [url]http://localhost/default.aspx?module=home[/url]
    will put a home.ascx in the place holder
    and
    eg [url]http://localhost/default.aspx?module=admin[/url]
    will put a admin.ascx in the place holder

    both the home and admin have its own folder respectively, where home.ascx is
    in /home folder and admin.ascx is in /admin folder.

    So I would like to implement form authentication, that if the user is not
    authenticated, when the default page is called with the parameter of
    module=admin, the user will be rejected.

    As normal i will create another web.config file in the folder and restrict
    all user which is not authenticated. However this did not work in my case
    where the page which is invoked is the default.aspx page regardless of all
    the .ascx files that are called.

    From the look of it only if i create an aspx file in the admin folder and
    call it like
    [url]http://localhost/admin/admin.aspx[/url] then the authentication will work where
    the user is rejected.

    Is there any way to use form authentication for this?, or would I have to do
    a different set of coding in the default page which will check if the ascx
    page being called is retricted or not?

    Or, would it be my design is totally wrong where i shouldn't have only a
    single aspx file calling different "module" which are totally coded as ascx
    files?

    Thanks in advance.

    Joey


    Joey Lee Guest

  2. Similar Questions and Discussions

    1. Using Contribute with aspx and ascx files - possible? How prevent editing of certain area?
      Has anyone tried using Contribute 3 or 4 with aspx pages or ascx user controls. What has been your experience? Does it work pretty well? Also,...
    2. Need help in FrameBased FormAuthentication
      Hi, We developed a frame based .net web application. And using FormAuthenticaion. Everyting works fine but whn session is timed out then login...
    3. FormAuthentication.SignOut NOT WORKING?? ANYONE KNOW THE ANSWER??
      I am using forms authentication in my web-apps. But I still could not make the formsAuthentication.signout to work. All the pages is added...
    4. [ASCX] Add an ascx in a webcontrol...
      hey there, ok i made a class, that inherits webcontrol, and i add an htmltable to it. I was wondering how to declare an ascx file as an object in...
    5. seperating ascx and cs files
      Hi, By default, code behind files (*.cs) and *.aspx files are located in the same folder. I want to separate my code behind files to a different...
  3. #2

    Default RE: FormAuthentication on ascx files



    Dear Joey,

    Your idea is good. But it doenst work as with normal when it comes to ascx
    files. Basically ascx files are not pages but parts of a page and they are
    rendered before the page is rendered.

    One way to restrict users would be is to put the following code in the
    codebehind of the usercontrol's page_load event as

    If(! Page.User.Identity.IsAuthenticated)
    {
    Response.Redirect("LoginPage.aspx");
    }

    This should help you in filtering anonymous calls to admin sections.

    Does that help.


    "Joey Lee" wrote:
    > Hi,
    >
    > I have a default.aspx page which has PlaceHolder where it will call
    > different *.acx file based on the request url.
    > eg [url]http://localhost/default.aspx?module=home[/url]
    > will put a home.ascx in the place holder
    > and
    > eg [url]http://localhost/default.aspx?module=admin[/url]
    > will put a admin.ascx in the place holder
    >
    > both the home and admin have its own folder respectively, where home.ascx is
    > in /home folder and admin.ascx is in /admin folder.
    >
    > So I would like to implement form authentication, that if the user is not
    > authenticated, when the default page is called with the parameter of
    > module=admin, the user will be rejected.
    >
    > As normal i will create another web.config file in the folder and restrict
    > all user which is not authenticated. However this did not work in my case
    > where the page which is invoked is the default.aspx page regardless of all
    > the .ascx files that are called.
    >
    > From the look of it only if i create an aspx file in the admin folder and
    > call it like
    > [url]http://localhost/admin/admin.aspx[/url] then the authentication will work where
    > the user is rejected.
    >
    > Is there any way to use form authentication for this?, or would I have to do
    > a different set of coding in the default page which will check if the ascx
    > page being called is retricted or not?
    >
    > Or, would it be my design is totally wrong where i shouldn't have only a
    > single aspx file calling different "module" which are totally coded as ascx
    > files?
    >
    > Thanks in advance.
    >
    > Joey
    >
    >
    >
    ranganh Guest

  4. #3

    Default Re: FormAuthentication on ascx files

    Thanks. That helps.

    However i am wondering what does it mean by "form authentication protects
    ascx files as well as all other a* files " which i read on the internet.

    Joey

    "ranganh" <ranganh@discussions.microsoft.com> wrote in message
    news:91795D04-E535-49E4-A96D-A636EC0B6B56@microsoft.com...
    >
    >
    > Dear Joey,
    >
    > Your idea is good. But it doenst work as with normal when it comes to
    ascx
    > files. Basically ascx files are not pages but parts of a page and they
    are
    > rendered before the page is rendered.
    >
    > One way to restrict users would be is to put the following code in the
    > codebehind of the usercontrol's page_load event as
    >
    > If(! Page.User.Identity.IsAuthenticated)
    > {
    > Response.Redirect("LoginPage.aspx");
    > }
    >
    > This should help you in filtering anonymous calls to admin sections.
    >
    > Does that help.
    >
    >
    > "Joey Lee" wrote:
    >
    > > Hi,
    > >
    > > I have a default.aspx page which has PlaceHolder where it will call
    > > different *.acx file based on the request url.
    > > eg [url]http://localhost/default.aspx?module=home[/url]
    > > will put a home.ascx in the place holder
    > > and
    > > eg [url]http://localhost/default.aspx?module=admin[/url]
    > > will put a admin.ascx in the place holder
    > >
    > > both the home and admin have its own folder respectively, where
    home.ascx is
    > > in /home folder and admin.ascx is in /admin folder.
    > >
    > > So I would like to implement form authentication, that if the user is
    not
    > > authenticated, when the default page is called with the parameter of
    > > module=admin, the user will be rejected.
    > >
    > > As normal i will create another web.config file in the folder and
    restrict
    > > all user which is not authenticated. However this did not work in my
    case
    > > where the page which is invoked is the default.aspx page regardless of
    all
    > > the .ascx files that are called.
    > >
    > > From the look of it only if i create an aspx file in the admin folder
    and
    > > call it like
    > > [url]http://localhost/admin/admin.aspx[/url] then the authentication will work
    where
    > > the user is rejected.
    > >
    > > Is there any way to use form authentication for this?, or would I have
    to do
    > > a different set of coding in the default page which will check if the
    ascx
    > > page being called is retricted or not?
    > >
    > > Or, would it be my design is totally wrong where i shouldn't have only a
    > > single aspx file calling different "module" which are totally coded as
    ascx
    > > files?
    > >
    > > Thanks in advance.
    > >
    > > Joey
    > >
    > >
    > >

    Joey Lee Guest

  5. #4

    Default Re: FormAuthentication on ascx files


    It refers to that forms authentication protects by default, the files
    handled by asp.net (aspnet_isapil.dll) such as aspx, ascx so that you dont
    have to exclusively map the extensions to be handled by asp.net

    Ok, say you want to protect a doc from being downloaded then along with
    forms authentication, you also need to specify the handler in the IIS to make
    asp.net handle the request for the doc type file. Else, it will be ignored
    and will be downloaded regardless of whether the user is logged in or not.

    Hope it clarifies.

    "Joey Lee" wrote:
    > Thanks. That helps.
    >
    > However i am wondering what does it mean by "form authentication protects
    > ascx files as well as all other a* files " which i read on the internet.
    >
    > Joey
    >
    > "ranganh" <ranganh@discussions.microsoft.com> wrote in message
    > news:91795D04-E535-49E4-A96D-A636EC0B6B56@microsoft.com...
    > >
    > >
    > > Dear Joey,
    > >
    > > Your idea is good. But it doenst work as with normal when it comes to
    > ascx
    > > files. Basically ascx files are not pages but parts of a page and they
    > are
    > > rendered before the page is rendered.
    > >
    > > One way to restrict users would be is to put the following code in the
    > > codebehind of the usercontrol's page_load event as
    > >
    > > If(! Page.User.Identity.IsAuthenticated)
    > > {
    > > Response.Redirect("LoginPage.aspx");
    > > }
    > >
    > > This should help you in filtering anonymous calls to admin sections.
    > >
    > > Does that help.
    > >
    > >
    > > "Joey Lee" wrote:
    > >
    > > > Hi,
    > > >
    > > > I have a default.aspx page which has PlaceHolder where it will call
    > > > different *.acx file based on the request url.
    > > > eg [url]http://localhost/default.aspx?module=home[/url]
    > > > will put a home.ascx in the place holder
    > > > and
    > > > eg [url]http://localhost/default.aspx?module=admin[/url]
    > > > will put a admin.ascx in the place holder
    > > >
    > > > both the home and admin have its own folder respectively, where
    > home.ascx is
    > > > in /home folder and admin.ascx is in /admin folder.
    > > >
    > > > So I would like to implement form authentication, that if the user is
    > not
    > > > authenticated, when the default page is called with the parameter of
    > > > module=admin, the user will be rejected.
    > > >
    > > > As normal i will create another web.config file in the folder and
    > restrict
    > > > all user which is not authenticated. However this did not work in my
    > case
    > > > where the page which is invoked is the default.aspx page regardless of
    > all
    > > > the .ascx files that are called.
    > > >
    > > > From the look of it only if i create an aspx file in the admin folder
    > and
    > > > call it like
    > > > [url]http://localhost/admin/admin.aspx[/url] then the authentication will work
    > where
    > > > the user is rejected.
    > > >
    > > > Is there any way to use form authentication for this?, or would I have
    > to do
    > > > a different set of coding in the default page which will check if the
    > ascx
    > > > page being called is retricted or not?
    > > >
    > > > Or, would it be my design is totally wrong where i shouldn't have only a
    > > > single aspx file calling different "module" which are totally coded as
    > ascx
    > > > files?
    > > >
    > > > Thanks in advance.
    > > >
    > > > Joey
    > > >
    > > >
    > > >
    >
    >
    >
    ranganh Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139