我正在尝试使用来自MVC 4控制器的以下代码访问其他asp.net应用程序中的web方法
using (WebClient client = new ReplicateUserControl())
{
string url = "http://localhost:1469/CMSPages/WebService.asmx/AuthWebMethod";
//List<string> getWidgetValue = new List<string>();
System.Collections.Specialized.NameValueCollection reqparm = new
System.Collections.Specialized.NameValueCollection();
reqparm.Add("Query", "changeTheme");
var getValue = client.UploadValues(url, "POST", reqparm);
}
以下是我的其他asp.net应用程序的web方法,该方法用于加载用户控件HTML数据并将其设置在一个列表字符串中。
[WebMethod(MessageName = "AuthWebMethod")]
public byte [] AuthWebMethod(string Query)
{
string getStringList = "";
byte[] setValue;
UserControl userControl;
using (Page page = new Page())
{
if (!string.IsNullOrEmpty(Query))
{
if (Query.ToUpper() == "USERINFO")
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
userControl = (UserControl)page.LoadControl(VirtualPathUtility.ToAbsolute("~/UserControls/Fortius.DreamTrips/UserInformation.ascx"));
userControl.RenderControl(hw);
getStringList += sb.ToString();
}
else if (Query.ToUpper() == "CHANGETHEME")
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
userControl = (UserControl)page.LoadControl(VirtualPathUtility.ToAbsolute("~/UserControls/Fortius.DreamTrips/DreamTrips_Themes.ascx"));
userControl.RenderControl(hw);
getStringList += sb.ToString();
}
}
}
setValue = System.Text.Encoding.UTF8.GetBytes(getStringList);
return setValue;
}
正如我们在这个web方法中看到的,我在列表字符串中加载用户控件HTML和脚本以及CSS。
我可以点击这个方法但是当它返回时我得到500 Internal Server Error
。