我有以下网址:
localhost:1088/Web_Market/A/Sport.aspx
它存储在一个字符串中,如下所示:
string str = "localhost:1088/Web_Market/A/Sport.aspx"
如何编辑字符串以便返回以下内容?
localhost:1088/Web_Market/A/
没有Sport.aspx
答案 0 :(得分:2)
使用以下代码
var provider = (DbProviderFactory)System.Data.Entity.DbConfiguration
.DependencyResolver
.GetService(typeof(DbProviderFactory), "invariant provider name");
var conn = provider.CreateConnection();
//conn.ConnectionString = "sample connection string";
DbInterception.Dispatch.Connection.SetConnectionString(conn, new DbConnectionPropertyInterceptionContext<string>()
.WithValue("sample connection string"));
return new SampleDbContext(conn,true);
这将在&#34; /&#34;的最后一次出现之前找到子字符串,它将获取您所需的URL。