Custom Textbox and Web site VS Web application

Discussion in 'ASP .Net Web Controls' started by Madison, Jun 18, 2007.

  1. Madison

    Madison Guest

    Hi All,
    I have created custom textbox in framework 2 and been using in asp.net
    framework 2 with Web Application Project mode everythinge works fine. Until
    I try to create new application by using Web Site Project mode, I add
    reference for custom textbox and add <controls> in web.config with
    <controls>
    <add tagPrefix="myControl" namespace="ccCustom.mycontrol"
    assembly="ccTextbox" />
    </controls>

    Then in the web page when I use custom control I get errors message say
    1. Request for the permission of type 'System.web.AspNetHostingPermission,
    System, Version=2.0.0.0, Culture=neutral, PublicKeyToken='b11a5c561934e089'
    failed.
    2. Element 'ccTextbox' is not a known elemetn. This can occur if there is a
    compilation error in the web site

    What is different setting between Web Application Project and Web Site
    Project?

    Any idea?
     
    Madison, Jun 18, 2007
    #1
    1. Advertising

  2. Hi Madison,

    From your description, when you try using a custom webserver control(in a
    separate class library assembly) as global registered control in web site
    application, you encoutner "request for
    'System.web.AspNetHostingPermission'" error ,correct?

    Regarding on this error message, I've ever seen some former threads & cases
    discussing on the similar problem, and most of them are caused by .NET cas
    code access security problem. So far I haven't found any different between
    "web site project" and " web application project" on this custom control
    behavior. Here are some causes you can check based on those former issues I
    found:

    ** You're referencing a 3rd party or external assembly which is compiled
    through .NET 1.X

    ** Your ASP.NET web application is not in "Full Trust" CAS level while your
    custom web control require Full Trust hoster

    ** Your ASP.NET web application web directory is on a UNC share that cause
    your ASP.NET application code be evaluated as Intranet zone (not full trust)

    Also, I've performed a very simple test as below:

    1) create a custom control class library that contains a custom control
    derived from TextBox (no additional code)

    2) create an ASP.NET 2.0 web site project and reference the class
    library(created in #1)

    3) use <pages><controls> to register the control as global one and use it
    in page

    the test applciation runs ok without problem. BTW, I use a file server(test
    server) project, If you're using IIS server, please feel free to let me
    know.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Jun 19, 2007
    #2
    1. Advertising

  3. Madison

    Madison Guest

    Hi Steven,

    Thank you for your reply.

    It is very helpful. I did created Web Application project under my localhost
    when I created Web Site project was under development server site (IIS
    server). So I did tried to create Web Site project under my localhost I did
    not have any problem with my custom textbox at all.

    What should I do to have full trust on development site server ?
    Do I will have any problems when I deploy this project to production web
    site server?

    I did not get any popup from
    Thank you for your advise.


    "Steven Cheng[MSFT]" wrote:

    > Hi Madison,
    >
    > From your description, when you try using a custom webserver control(in a
    > separate class library assembly) as global registered control in web site
    > application, you encoutner "request for
    > 'System.web.AspNetHostingPermission'" error ,correct?
    >
    > Regarding on this error message, I've ever seen some former threads & cases
    > discussing on the similar problem, and most of them are caused by .NET cas
    > code access security problem. So far I haven't found any different between
    > "web site project" and " web application project" on this custom control
    > behavior. Here are some causes you can check based on those former issues I
    > found:
    >
    > ** You're referencing a 3rd party or external assembly which is compiled
    > through .NET 1.X
    >
    > ** Your ASP.NET web application is not in "Full Trust" CAS level while your
    > custom web control require Full Trust hoster
    >
    > ** Your ASP.NET web application web directory is on a UNC share that cause
    > your ASP.NET application code be evaluated as Intranet zone (not full trust)
    >
    > Also, I've performed a very simple test as below:
    >
    > 1) create a custom control class library that contains a custom control
    > derived from TextBox (no additional code)
    >
    > 2) create an ASP.NET 2.0 web site project and reference the class
    > library(created in #1)
    >
    > 3) use <pages><controls> to register the control as global one and use it
    > in page
    >
    > the test applciation runs ok without problem. BTW, I use a file server(test
    > server) project, If you're using IIS server, please feel free to let me
    > know.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
     
    Madison, Jun 19, 2007
    #3
  4. Hi Madison,

    Thanks for your reply.

    So based on your further information, the problem occurs when you use an
    web site application that hosted in local IIS server, correct?

    I think you can check your IIS application virtual directory's directory
    path, whether it is under the default wwwroot location or pointed to an
    external directory path(such as to a user's "MyDocument path" or to a
    remote UNC share? If the IIS virtual directory's physical path is from a
    non-local directory(such as a unc share) ,it may be evaluated as
    non-FullTrust context. Also, you can add the following configuration
    setting in your application's web.config to force the application level CAS
    permission be configured as "FullTrust" level.

    =============
    .........
    <trust level="Full"/>
    </system.web>
    ==================

    In addition, you can also try creating other new web application in IIS to
    test the same behavior.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Jun 21, 2007
    #4
  5. Hi Madison,

    How are you doing on this? Does the further reply helps you some? If there
    is anything else we can help, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Jun 25, 2007
    #5
  6. Madison

    Madison Guest

    Hi Steven,

    Sorry for delay your response.
    I have tried to add <trust level="Full" /> in web.config and yes the IIS
    application virtual directory's directory path is pointed to a remote UNC
    share which all our web pages and applications reside. I still get the
    message say

    Element 'myControl' is not a known element. This can occur if there is a
    compilation error in the Web site

    and the properties did not show when I start to type.

    Thank you for your help.

    Madison
     
    Madison, Jun 25, 2007
    #6
  7. Thanks for your reply Madison,

    Well, I think the fact that IIS virtual directory's home path pointing to a
    remote UNC share is a important hints. As I mentioned earlier, for UNC
    share path, .net framework CAS policy will evaluate it as "Local Intranet"
    zone which is not of "FullTrust" permission. You need to add a new
    codegroup in machine level CAS policy and grant full permission to it. The
    detailed steps is as below:

    ** In server's control panel->administrative tools, start ".NET 2.0
    CONFIGURATION " tool

    **In left view, select "Mycomputer--> Runtime security policy--->
    machine--->code g roups" node

    **You can add a new code group under the "All_Code" group, give it a name.
    In the "condition for this code group", select "Url" and input your remote
    UNC share's path in it (as below):

    \\servername\sharename\*

    In "PermissionSet" , give it "FullTrust"

    Save it and run your application again to see the behavior. Here is a web
    article introducing .NET CAS and how to configure codegroup setting.

    #Configuring .NET Code Access Security
    http://www.15seconds.com/issue/040121.htm

    and for ASP.NET specific code access information, you can have a look at
    the following articles:

    #Chapter 9 ┬ĘC Using Code Access Security with ASP.NET
    http://msdn2.microsoft.com/En-US/library/aa302425.aspx

    #How To: Use Code Access Security in ASP.NET 2.0
    http://msdn2.microsoft.com/en-us/library/ms998326.aspx

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Jun 27, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mike kim
    Replies:
    2
    Views:
    538
    clintonG
    Aug 20, 2003
  2. Lloyd Sheen
    Replies:
    1
    Views:
    344
    Lloyd Sheen
    Nov 15, 2007
  3. Bill Anderson

    Custom Component and Custom Textbox binding

    Bill Anderson, Dec 10, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    489
    Bill Anderson
    Dec 15, 2003
  4. John Wright

    Custom TextBox with custom attributes and properties question

    John Wright, Feb 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    211
    John Wright
    Mar 1, 2004
  5. CNA Programming Group

    Custom web design and web site development

    CNA Programming Group, Aug 31, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    116
Loading...

Share This Page