100分急求获得服务器动太IP的方法,周一就要叫差了,特地开新个帐户散分了 一个DLL中封装了提供WEBSERVICE服务的服务器IP,可现在才知道服务器的IP不明确,怎么才能动态的在配置文件WEB.config中动态绑定呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先using System.Net;用Dns.Resolve(Dns.GetHostName()).AddressList[i](i为第几个网络连接是外网,就是几)获得网站服务器的IP! 具体情况:我用HttpModule做了个截取筛选器(MyModule.dll),作用是当访问重要页面前必须调用一个WebService,这个WebServic根据2个参数返回一个User,现在的问题是MyModule.dll中引用了发布WebService的服务器IP,可这个IP现在不确定,可能会变,我觉得说应该可以在配置文件中写成自动捕获的,可我查了半天网不知从何下手??? 代码如下:using System;using System.Web;using System.Security.Principal;using System.Diagnostics;namespace MyModule{ /// <summary> /// Class1 的摘要说明。 /// </summary> public class SyncModule : IHttpModule //必须继承IHttpModule接口 { private HttpApplication httpApp; public void Init(HttpApplication httpApp) { this.httpApp = httpApp; httpApp.AuthenticateRequest += new EventHandler(OnAuthentication);//在Init中注册 } void OnAuthentication(object sender, EventArgs a)//OnAuthentication是在将要验证时自动引发 { HttpApplication application = (HttpApplication)sender; HttpResponse response = application.Context.Response; WebReference.UserServiceBinding binding = new WebReference.UserServiceBinding();//构造代理类 WebReference.User user=binding.Authenticate(application.Request.Params.Get("token"),application.Request.UserHostAddress);//根据字符串token和请求者的IP返回一个User对象 if (user==null) { string failPage=System.Configuration .ConfigurationSettings .AppSettings ["failPage"];//如果对象不存在,就导航到指定错误页面,具体页面在用户的WebConfig中配置 response.Redirect("failPage",true); } } public void Dispose() {} }} 申请一下域名,比如www.mywebservice.com然后,服务器IP换了后更新域名指向就可以了,程序不用运.然后你的程序里使用域名来连接. 把webservic的访问url配到web.config中WebReference.UserServiceBinding binding = new WebReference.UserServiceBinding();//构造代理类binding.Url=System.Configuration.ConfigurationSettings.AppSettings["MyWebServiceUrl"];.... 那MyWebServiceUrl是KEY,但VALUE怎么写呢 http://10.199.1.1/test/myService.asmx这样的 日期问题· 关于分析器错误的问题! GridView 与 ObjectDataSource 打開一个無最大和最小窗體,放在右下角 关于WebConfig中字符串连接的一个非常棘手的问题!(急)解决就给分 大家给点思路:如何在DataGrid外面,是按钮控制增删改 我asp.net项目解决方案的文件、类库不见了。 如何实现上传多个附件并反回值给调用页面?效果要像发邮件那样的! 在.net studio 中编辑的.aspx网页无法显示的问题!急!!!100分相送! 怎样重新运行pageload函数? 在线结分:不能更新,也不报错的问题 各位大侠请教一个关于传给JAVAScrip函数参数过长的问题
using System.Net;
用
Dns.Resolve(Dns.GetHostName()).AddressList[i](i为第几个网络连接是外网,就是几)
获得网站服务器的IP!
using System.Web;
using System.Security.Principal;
using System.Diagnostics;namespace MyModule
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class SyncModule : IHttpModule //必须继承IHttpModule接口
{
private HttpApplication httpApp; public void Init(HttpApplication httpApp)
{
this.httpApp = httpApp;
httpApp.AuthenticateRequest += new EventHandler(OnAuthentication);//在Init中注册
} void OnAuthentication(object sender, EventArgs a)//OnAuthentication是在将要验证时自动引发
{
HttpApplication application = (HttpApplication)sender;
HttpResponse response = application.Context.Response;
WebReference.UserServiceBinding binding = new WebReference.UserServiceBinding();//构造代理类
WebReference.User user=binding.Authenticate(application.Request.Params.Get("token"),application.Request.UserHostAddress);//根据字符串token和请求者的IP返回一个User对象
if (user==null)
{
string failPage=System.Configuration .ConfigurationSettings .AppSettings ["failPage"];//如果对象不存在,就导航到指定错误页面,具体页面在用户的WebConfig中配置
response.Redirect("failPage",true);
}
}
public void Dispose()
{} }
}
binding.Url=System.Configuration.ConfigurationSettings.AppSettings["MyWebServiceUrl"];
....