Showing posts with label scriptmanager. Show all posts
Showing posts with label scriptmanager. Show all posts

Wednesday, March 28, 2012

AJAX based Web service authentication issue

Hi, I have created a webservice for putting overlays on googlemap. I am using scriptmanager to generate java proxy class. Everything works as expected as long as I use localhost in the url e.g.http://localhost/test.aspx orhttp://localhost/map.asmx/js but if I use the actual domain name then it don't work anymore e.g.http://www.test.com/test.aspx orhttp://www.test.com/map.asmx/js. In case of IE7 i get script error 'test is undefined' and in case of Firefox, I get authentication failed. The result is same whether I run it on the server or on the client. I have tried every possible thing that I can think of. Environment is Win 2003 and IIS 6.0. Framework 2.0 is enabled in the web services entensions. I am using windows integrated authentication and anonymous access is also enable. I am new to ajax world and trying hard for last 2 days to solve this problem. Please help me. Thanks a lot

Hi,

Can you directly browse to http://www.test.com/map.asmx/js. and does that download the Script Proxy ?

Also , can you take a look at the IIS Logs to understand the behavior on the server when you browse to the page ?

Go to Start --> Run -->Type in "LogFiles"

In the folder that opens up , go inside W3SVC1.

Take a look at the File exmmddyy.log and paste the lines that havemap.asmx/js. here.


Thanks for quick response. When I directly browse to .../js in IE7, i get 500 internal error whereas in case of Firefox, it prompts to download a file and the contents of the file are: "{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}".

No such folder "W3SVC1" exists under LogFiles ... only following folders are present there "Cluster, HTTPERR, ShutDown" and in there I am not able to find anything related to my issue.

Please let me know what next I should do? Thanks


Hi,

HttpPost andHttpGet for webservices is disabled by default in ASP.net 2.0

See if you can find the following snippet in your web.config , if it doesnt exist, add it under the <System.Web> Tag

<webServices>
<protocols>
<add name="HttpSoap1.2"/>
<add name="HttpSoap"/>
<add name="HttpPost"/> // uncomment this
<add name="HttpGet"/> // uncomment this
<add name="HttpPostLocalhost"/>
<add name="Documentation"/>
</protocols>
<soapExtensionTypes>
</soapExtensionTypes>
<soapExtensionReflectorTypes>
</soapExtensionReflectorTypes>
<soapExtensionImporterTypes>
</soapExtensionImporterTypes>
<wsdlHelpGenerator href="http://links.10026.com/?link=DefaultWsdlHelpGenerator.aspx"/>
<serviceDescriptionFormatExtensionTypes>
</serviceDescriptionFormatExtensionTypes>
</webServices>

Hope this helps


Read this KB article about Protocols and web services

HOW TO: Limit the Web Services Protocols that a Server Permits

http://support.microsoft.com/?id=815150


Yes, it was not there and I copied it under system.web tag but the issue is still there. There is also an <httpHandles> tag under system.web. I am pasting the lines from my web.config related to ajax. May be it will give further clue. Please let me know if u see something wrong there or what should I do next. Thanks a lot.

--------

<configSections>
<sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionGroupname="scripting" type="System.Web.Configuration.ScriptingSectionGroup,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionname="scriptResourceHandler"type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />
<sectionGroup name="webServices"type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35">
<sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="Everywhere" />
<sectionname="profileService"type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />

<section name="authenticationService"type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" requirePermission="false"allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
<sectionGroup name="applicationSettings"type="System.Configuration.ApplicationSettingsGroup, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="wwwroot.Properties.Settings"type="System.Configuration.ClientSettingsSection, System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"requirePermission="false" />
</sectionGroup>
</configSections>

<system.web>

<httpHandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<add verb="*"path="*_AppService.axd" validate="false"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<addverb="GET,HEAD" path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false" />

</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ScriptModule" preCondition="integratedMode"type="System.Web.Handlers.ScriptModule, System.Web.Extensions,Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory,System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
<addname="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ScriptResource" preCondition="integratedMode"verb="GET,HEAD" path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>

----------------


I have found the iis logfiles and the directory 'W3SVC1' ... this directory is present in another partition because of setting different path for logging from IIS console.

Below are the lines related to this webservice:

this is the line when called with the following url : http://localhost/WebServices/WSGoogleMaps.asmx

2007-02-22 17:06:54 127.0.0.1 GET /webservices/wsgooglemaps.asmx/js - 80 - 127.0.0.1 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 200 0 0

and this is the line when called with the following url: http://mytest.server.com/WebServices/WSGoogleMaps.asmx

2007-02-22 18:15:27 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 132.136.112.84 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+InfoPath.2;+.NET+CLR+2.0.50727;+.NET+CLR+1.1.4322) 500 0 0

I have tried it on the server itself as well. If I use domainname then it is giving 500 internal error in IE7 or authentication failed in Firefox. This is the line when called from the server itself using domain name:

2007-02-22 16:41:04 192.167.1.273 GET /WebServices/WSGoogleMaps.asmx/jsdebug - 80 - 192.167.1.273 Mozilla/5.0+(Windows;+U;+Windows+NT+5.2;+en-US;+rv:1.8.1.1)+Gecko/20061204+Firefox/2.0.0.1 500 0 0

I simply don't understand that how same code on the same machine works with localhost in the url but gives error when called with domain name in the url. I am totally lost. Please help me solve it ... I need to solve it urgently. Thanks.


Hi there,

We are experiencing the same issue that seems to do with the domain name causing the authentication error in some environments. Did you ever get a resolution to this issue?

Saturday, March 24, 2012

AJAX and user controls

Hi

First of all, I use AJAX 1.0. I have bumped into following problem. I have aspx page (Default.aspx) with ScriptManager on it. It has header, left menu and content layout. On each of those I have UpdatePanel in which I have PlaceHolder. I use those placeholders to load uc controls.

What I want to acheive is to load default uc-s in every ph on Page Load which works ok. Menu ph will always have default uc loaded. When I click on menu item (which is in menu control on menu uc in menu ph), I want to change header uc and content uc -> load new uc-s in their ph-s. This also works ok but I doubt my method in acheiving this.

My page load code:

1using System;2using System.Data;3using System.Configuration;4using System.Web;5using System.Web.Security;6using System.Web.UI;7using System.Web.UI.WebControls;8using System.Web.UI.WebControls.WebParts;9using System.Web.UI.HtmlControls;1011public partialclass _Default : System.Web.UI.Page12{13#region UC ViewState14public string currentUCM15 {16get17 {18if (ViewState["currentUCM"] !=null)return ViewState["currentUCM"].ToString();19else return null;20 }21set { ViewState["currentUCM"] =value; }22 }23public string currentUCH24 {25get26 {27if (ViewState["currentUCH"] !=null)return ViewState["currentUCH"].ToString();28else return null;29 }30set { ViewState["currentUCH"] =value; }31 }32public string currentUCC33 {34get35 {36if (ViewState["currentUCC"] !=null)return ViewState["currentUCC"].ToString();37else return null;38 }39set { ViewState["currentUCC"] =value; }40 }41#endregion4243 protected void Page_Load(object sender, EventArgs e)44 {45// menu46if (currentUCM !=null)47 {48 phMenu.Controls.Add(LoadControl(currentUCM));49 }50else51 {52 currentUCM ="~/uc/uc_m1.ascx";53 phMenu.Controls.Add(LoadControl(currentUCM));54 }5556// head57if (currentUCH !=null)58 {59 phHead.Controls.Add(LoadControl(currentUCH));60 }61else62 {63 currentUCH ="~/uc/uc_h1.ascx";64 phHead.Controls.Add(LoadControl(currentUCH));65 }6667// content68if (currentUCC !=null)69 {70 phMainContent.Controls.Add(LoadControl(currentUCC));71 }72else73 {74 currentUCC ="~/uc/uc_c1.ascx";75 phMainContent.Controls.Add(LoadControl(currentUCC));76 }77 }78}
Code in my uc_m1.ascx (menu) is as follows:  
1using System;2using System.Data;3using System.Configuration;4using System.Collections;5using System.Web;6using System.Web.Security;7using System.Web.UI;8using System.Web.UI.WebControls;9using System.Web.UI.WebControls.WebParts;10using System.Web.UI.HtmlControls;1112public partialclass uc_uc_m1 : System.Web.UI.UserControl13{14protected void Page_Load(object sender, EventArgs e)15 {1617 }1819protected void mnuMain_MenuItemClick(object sender, MenuEventArgs e)20 {21string currentUCM ="~/uc/uc_m" + e.Item.Value +".ascx";22string currentUCH ="~/uc/uc_h" + e.Item.Value +".ascx";23string currentUCC ="~/uc/uc_c" + e.Item.Value +".ascx";2425// setting ViewState on page26 Page.GetType().GetProperty("currentUCM").SetValue(this.Page, currentUCM,null);27 Page.GetType().GetProperty("currentUCH").SetValue(this.Page, currentUCH,null);28 Page.GetType().GetProperty("currentUCC").SetValue(this.Page, currentUCC,null);2930 PlaceHolder phH = (PlaceHolder)this.Page.FindControl("phHead");31 phH.Controls.Clear();32 phH.Controls.Add(LoadControl(currentUCH));3334 PlaceHolder phC = (PlaceHolder)this.Page.FindControl("phMainContent");35 phC.Controls.Clear();36 phC.Controls.Add(LoadControl(currentUCC));3738// debug39 lblClicked.Text = (Convert.ToInt32(lblClicked.Text) + 1).ToString();40 }41}42
...here I set what gets loaded and override Page Load-s loaded controls, and then use reflection to set ViewState on Page through public property. I tried
to use ViewState directly, but didn't work. Can I update ViewState somehow?
Anyway, when I do this, I get "Failed to load viewstate...control tree doesn't match...".
Is there a way to go arround this? Another solution? Because I would like to use those similar to windows forms, just open form I need. And those uc I load
will have forms on them.
Thanx
If I remove reflection, leave ViewState as is and simply put another update panel in each UC, can I then refresh page only inside UC's update panel and refresh *global update panel based on condition?
Ok, I solved ViewState problem by simply using Session instead. It works better but not correct yet. Also there might be bug in AJAX, I have script error on page saying 0.cells is not object. Problem that remains is how to postback on uc control. My first postback doesnt work, only next ones do. I think it is because of event registration happening too late.

Ajax and MasterPage issues (tags like scriptManager and html - not recognized)

I am having problem with AJAX Toolkit and MasterPages.

When I create a new Content Page and use html tags or ahax scriptManager I recevied lots of errors.

I cannot seem to get this resolved.

Here find below example I am working on - none of the html or scriptManager stuff for ajax is being recongnised.

Please assist.

File Sample

------------

<%@dotnet.itags.org.PageLanguage="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup="true"CodeFile="laz.aspx.cs"Inherits="laz"Title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

</asp:Content>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">

protectedvoid btnRefresh_Click(object sender,EventArgs e)

{

}

</script>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Untitled Page</title>

<linkhref="StyleSheet.css"rel="stylesheet"type="text/css"/>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:PanelID="Panel1"runat="server"CssClass="modalPopup"Height="50px"Width="235px"style="display:none"DefaultButton="btnOk">

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">

<ContentTemplate>

<%=DateTime.Now.ToString() %>

<divstyle="display:none">

<asp:ButtonID="btnRefresh"runat="server"Text="Refresh"OnClick="btnRefresh_Click"/>

</div>

</ContentTemplate>

</asp:UpdatePanel>

<asp:ButtonID="btnCancel"runat="server"Text="Cancel"/>

<asp:ButtonID="btnOk"runat="server"Text=" OK "/>

</asp:Panel>

<asp:ButtonID="Button2"runat="server"Text="Button"Enabled="false"style="display:none"/>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="Button2"PopupControlID="Panel1"CancelControlID="btnCancel"DropShadow="true"BackgroundCssClass="modalBackground">

</ajaxToolkit:ModalPopupExtender>

<inputid="Button3"type="button"value="Click Me"onclick="showModalPopup()"/>

<scripttype="text/javascript"language="javascript">

function showModalPopup(){

$get("<%=btnRefresh.ClientID %>").click();

$find("<%= this.ModalPopupExtender1.ClientID %>").show();

}

</script>

</form>

</body>

</html>

...........?

why are all the tags outside the <asp:Content? Aren't they suppose to be inside?


Honestly is does not matter if the content is inside the ASP tag or not. I was testing the contents outside. Here find the same results with ASP tag and content inside.

With the below I receive 7 errors

1. Only content controls allowed directly in content page. LINE 16

2. Validation XHTML 1.0 Element body cannot be in nested within <div> - I do not have div tag in ths aspx page but maybe it comes from the masterpage? LINE 14

3. Element Script Manager not a knwon element LINE 16

4. Element UpdatePanel unknown element LINE 19

5. Validation Element contenttemplate is not supported LINE 20

6. Element Button is not a known element Line 23

<%@.PageLanguage="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup="true"CodeFile="laz.aspx.cs"Inherits="laz"Title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<scriptrunat="server">

protectedvoid btnRefresh_Click(object sender,EventArgs e)

{

}

</script>

<body> LINE 14

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"> LINE 16

</asp:ScriptManager>

<asp:PanelID="Panel1"runat="server"CssClass="modalPopup"Height="50px"Width="235px"style="display:none"DefaultButton="btnOk">

<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"> LINE 19

<ContentTemplate> LINE 20

<%=DateTime.Now.ToString() %>

<divstyle="display:none">

<asp:ButtonID="btnRefresh"runat="server"Text="Refresh"OnClick="btnRefresh_Click"/> LINE 23

</div>

</ContentTemplate>

</asp:UpdatePanel>

<asp:ButtonID="btnCancel"runat="server"Text="Cancel"/>

<asp:ButtonID="btnOk"runat="server"Text=" OK "/>

</asp:Panel>

<asp:ButtonID="Button2"runat="server"Text="Button"Enabled="false"style="display:none"/>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="Button2"PopupControlID="Panel1"CancelControlID="btnCancel"DropShadow="true"BackgroundCssClass="modalBackground">

</ajaxToolkit:ModalPopupExtender>

<inputid="Button3"type="button"value="Click Me"onclick="showModalPopup()"/>

<scripttype="text/javascript"language="javascript">

function showModalPopup(){

$get("<%=btnRefresh.ClientID %>").click();

$find("<%= this.ModalPopupExtender1.ClientID %>").show();

}

</script>

</form>

</body>

</asp:Content>


from what you have here is that you have a <body> and <form> tags; those normally are already declared in the MasterPage. Check it again.


Yes I added the tags in Master page and removed from content page.

Also I added a masterpage.master.vb file and applied the imports which solved the issue with the scriptmanager.

Wednesday, March 21, 2012

Ajax and compile problem

Hey all,

I have a page with a gridview on it, when I put a scriptmanager and an update panel and the put the gv in the panel and publish I get an "the file xxx has not been precompiled and connot be requested" error. If i remove the ajax controls everything works ok, what have I done wrong?

tia

That seems like an odd problem to me. I'm using VS2005, and have the latest AJAX beta installed. I'm using gridviews and datalists in update panels and don't have any problems with them. Can you post more about your setup?